package com.demo.controller;


import com.demo.entity.VteRiskScoreItem;
import com.demo.response.Result;
import com.demo.service.IVteRiskScoreItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * VTE风险评估项目 前端控制器
 *
 * @author zm
 * @since 2020-11-25
 */
@RestController
@Api(tags = "VTE风险评估项目")
@RequestMapping("/vteRiskScoreItem")
public class VteRiskScoreItemController {
    @Autowired
    IVteRiskScoreItemService iVteRiskScoreItemService;

    @ApiOperation("新增VTE风险评估项")
    @PostMapping("/addVteRiskScoreItem")
    public Result addVteRiskScoreItem(@Validated @RequestBody VteRiskScoreItem vteRiskScoreItem, BindingResult result) {
        if (result.hasErrors()) {
            return Result.error(result.getFieldError().getDefaultMessage());
        }
        return iVteRiskScoreItemService.addVteScoreItem(vteRiskScoreItem);
    }

    @ApiOperation("更新VTE风险评估项")
    @PostMapping("/updateVteRiskScoreItem")
    public Result updateVteRiskScoreItem(@RequestBody VteRiskScoreItem vteRiskScoreItem, BindingResult result) {
        if (result.hasErrors()) {
            return Result.error(result.getFieldError().getDefaultMessage());
        }
        return iVteRiskScoreItemService.updateVteScoreItem(vteRiskScoreItem);
    }

    @ApiOperation("删除VTE风险评估项")
    @GetMapping("/deleteVteRiskScoreItem")
    public Result deleteVteRiskScoreItem(@RequestParam(name = "vteItemId") Integer vteItemId,
                                         @RequestParam(name = "deletedUserId") Integer deletedUserId) {
        return iVteRiskScoreItemService.deleteVteScoreItem(vteItemId, deletedUserId);
    }

    @ApiOperation("VTE风险评估项列表")
    @GetMapping("/vteRiskScoreItemList")
    public Result vteRiskScoreItemList(@RequestParam(name = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
                                       @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                       @RequestParam(name = "vteItemName", required = false) String vteItemName,
                                       @RequestParam(name = "vtePreventiveId", required = false) Integer vtePreventiveId,
                                       @RequestParam(name = "allItem", required = false, defaultValue = "false") Boolean allItem) {
        return iVteRiskScoreItemService.vteScoreItemList(pageNumber, pageSize, vteItemName, vtePreventiveId, allItem);
    }

}
